import java.util.Date;

class Loan {
    private double annualInterestRate; // 年利率
    private int numberOfYears;        // 贷款年数
    private double loanAmount;        // 贷款额
    private Date loanDate;            // 贷款日期

    // (1) 默认的无参构造方法
    public Loan() {
        this(2.5, 1, 100); // 使用默认值
    }

    // (2) 带指定利率、年数和贷款额的构造方法
    public Loan(double annualInterestRate, int numberOfYears, double loanAmount) {
        // 校验输入是否合法
        if (annualInterestRate <= 0) {
            throw new IllegalArgumentException("Annual interest rate must be positive");
        }
        if (numberOfYears <= 0) {
            throw new IllegalArgumentException("Number of years must be positive");
        }
        if (loanAmount <= 0) {
            throw new IllegalArgumentException("Loan amount must be positive");
        }

        this.annualInterestRate = annualInterestRate;
        this.numberOfYears = numberOfYears;
        this.loanAmount = loanAmount;
        this.loanDate = new Date(); // 设置为当前日期
    }

    // (3) 所有属性的 get/set 方法
    public double getAnnualInterestRate() {
        return annualInterestRate;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        if (annualInterestRate <= 0) {
            throw new IllegalArgumentException("Annual interest rate must be positive");
        }
        this.annualInterestRate = annualInterestRate;
    }

    public int getNumberOfYears() {
        return numberOfYears;
    }

    public void setNumberOfYears(int numberOfYears) {
        if (numberOfYears <= 0) {
            throw new IllegalArgumentException("Number of years must be positive");
        }
        this.numberOfYears = numberOfYears;
    }

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        if (loanAmount <= 0) {
            throw new IllegalArgumentException("Loan amount must be positive");
        }
        this.loanAmount = loanAmount;
    }

    public Date getLoanDate() {
        return loanDate;
    }

    // (4) 返回这笔贷款的月支付额
    public double getMonthlyPayment() {
        double monthlyInterestRate = annualInterestRate / 1200; // 月利率 = 年利率 / 12
        int numberOfPayments = numberOfYears * 12; // 总支付次数 = 年数 * 12
        double monthlyPayment = (loanAmount * monthlyInterestRate) /
                (1 - (1 / Math.pow(1 + monthlyInterestRate, numberOfPayments)));
        return monthlyPayment;
    }

    // (5) 返回这笔贷款的总支付额
    public double getTotalPayment() {
        return getMonthlyPayment() * numberOfYears * 12;
    }
}